<%--
  Created by IntelliJ IDEA.
  User: yangbushudemao
  Date: 2021/5/11
  Time: 10:04
  To change this template use File | Settings | File Templates.
--%><%@include file="/common/common.jsp" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
</head>
<body>
    <div class="zTreeDemoBackground left">
    <ul id="treeDemo" class="ztree"></ul>
    </div>
</body>
</html>
    <script>
    <!--
    var setting = {
            check: { // 显示复选框
                enable: true,
                autoCheckTrigger: true
            },
            async:{
                enable:true,
                dataType:"json",
                url: "<%=path%>/menuController/getMenuZtree"
             },
            view : {
            addHoverDom: function(treeId, treeNode){
            var aObj = $("#" + treeNode.tId + "_a");
            if (treeNode.editNameFlag || $("#btnGroup"+treeNode.tId).length>0) return;
            var s = '<span id="btnGroup'+treeNode.tId+'">';
            if (treeNode.children == undefined) {
            s += '<a class="btn btn-info dropdown-toggle btn-xs" style="margin-left:10px;padding-top:0px;" onclick="deleteNode('+treeNode.id+')" href="#" >删除</a>';
            s += '<a class="btn btn-info dropdown-toggle btn-xs" style="margin-left:10px;padding-top:0px;"  onclick="upDateNode('+treeNode.id+')" href="#" title="修改权限信息">修改</a>';
            s += '<a class="btn btn-info dropdown-toggle btn-xs" style="margin-left:10px;padding-top:0px;" onclick="addNode('+treeNode.id+')" href="#" >添加</a>';
            }else{
            s += '<a class="btn btn-info dropdown-toggle btn-xs" style="margin-left:10px;padding-top:0px;"  onclick="upDateNode('+treeNode.id+')" href="#" title="修改权限信息">修改</a>';
            s += '<a class="btn btn-info dropdown-toggle btn-xs" style="margin-left:10px;padding-top:0px;" onclick="addNode('+treeNode.id+')" href="#" >添加</a>';
            }
            s += '</span>';
            aObj.after(s);
            },
            removeHoverDom: function(treeId, treeNode){
            $("#btnGroup"+treeNode.tId).remove();
            }
            }
        };


    $(document).ready(function(){
         $.fn.zTree.init($("#treeDemo"), setting);
    });
    //-->
    function addNode(id){
         BootstrapDialog.show({
         title: '增加',
         message: $('<div></div>').load("<%=path%>/menuController/toAdd"),
         buttons: [{
         label: '关闭',
         action: function (dialog) {
         dialog.close();
         }
         }, {
         label: '确定',
         action: function (dialog) {
         $.ajax({
         url : "<%=path%>/menuController/addMenuInfo",
         type : "post",
         data : $("#menuAdd").serialize() + "&pid=" + id,
         dataType : "json",
         success : function (result){
         toastr.success("增加成功");
         //关闭窗口
         dialog.close();
         //树形控件
         $.fn.zTree.init($("#treeDemo"), setting);
         },
         error : function (result){
         alert("请联系管理员");
         }
         })
         }
         }]
         });
         }
    function upDateNode(id) {
        BootstrapDialog.show({
            title:"修改",
            message:$('<div></div>').load("<%=path%>/menuController/toUpdate/" + id),
            buttons:[{
                label:"关闭",
                action:function(dialog) {
                     dialog.close();
                }
            }, {
                label: "确认",
                action:function(dialog) {
                     $.ajax({
                     url : "<%=path%>/menuController/updateMenuInfo",
                     type : "post",
                     data : $("#updateForm").serialize(),
                     dataType : "json",
                     success : function (result){
                     toastr.success("修改成功");
                     dialog.close();
                     $.fn.zTree.init($("#treeDemo"), setting);
                     },
                     error : function (result){
                     alert("请联系管理员");
                     }
                     })
                }
                }]
         })
    }
    function deleteNode(id) {
    if(confirm("宝,确定删我吗?")){
                    $.ajax({
                        url : "<%=path%>/menuController/deleteMenuInfo/" + id,
                        type : "post",
                        dataType : "json",
                        success : function (result){
                            toastr.success("删除成功");
                            $.fn.zTree.init($("#treeDemo"), setting);
                        },
                        error : function (result){
                            alert("请联系管理员");
                        }
                    })
                }
    }
    </script>